<template>
  <el-container class="home-container">
    <!-- 头部菜单 -->
    <el-header>
      <div class="box_loop">
        <div class="box_img">
          <img src="../assets/微信图片_20210929141511.jpg" alt="" />
        </div>
        <span>电商后台管理系统</span>
      </div>
      <el-button type="info" @click="Out">退出</el-button>
    </el-header>
    <el-container>
      <!-- 侧边栏菜单 -->
      <el-aside :width="iscollapse ? '64px' : '200px'">
        <div class="toggle" @click="collpe">|||</div>
        <el-row>
          <el-col>
            <el-menu
              background-color="#545c64"
              text-color="#fff"
              active-text-color="#409EFF"
              :unique-opened="true"
              :collapse="iscollapse"
              :collapse-transition="false"
              router
              :default-active="act"
            >
              <el-submenu
                :index="item.id + ''"
                v-for="item in mentslist"
                :key="item.id"
              >
                <template slot="title">
                  <i :class="aute[item.id]"></i>
                  <span>{{ item.authName }}</span>
                </template>

                <el-menu-item
                  :index="el.path"
                  v-for="el in item.children"
                  :key="el.id"
                  @click="save(el.path)"
                >
                  <template slot="title">
                    <span>{{ el.authName }}</span>
                  </template>
                </el-menu-item>
              </el-submenu>
            </el-menu>
          </el-col>
        </el-row>
      </el-aside>

      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import uri from "../config/uri";
export default {
  data() {
    return {
      mentslist: [],
      aute: {
        125: "iconfont icon-user",
        103: "iconfont icon-tijikongjian",
        101: "iconfont icon-shangpin",
        102: "iconfont icon-danju",
        145: "iconfont icon-baobiao",
      },
      // 是否折叠
      iscollapse: false,
      //   保存被点击激活的地址
      act: "",
    };
  },
  created() {
    this.gethome();
    this.act=window.sessionStorage.getItem("act")
  },
  methods: {
    Out() {
      window.sessionStorage.removeItem("token");
       window.sessionStorage.removeItem("act");
      this.$router.push("/login");
    },
    gethome() {
      this.$http.get(uri.getmunts).then((res) => {
        // console.log(res);
        if (res.meta.status === 200) {
          this.mentslist = res.data;
        }
      });
    },
    collpe() {
      this.iscollapse = !this.iscollapse;
    },
    save(act) {
      window.sessionStorage.setItem("act", act);
      this.act = act
    },
  },
};
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
}
.el-header {
  background-color: #3d3d3d;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0;
  padding-right: 20px;
  .box_loop {
    display: flex;
    align-items: center;
    span {
      font-size: 20px;
      color: #fff;
      margin-left: 20px;
    }
  }
  .box_img {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    overflow: hidden;
    img {
      width: 100%;
    }
  }
}
.el-aside {
  background-color: #545c64;
  height: 100%;

  .el-menu {
    border: none;
  }
}
.iconfont {
  margin-right: 10px;
}
.toggle {
  width: 100%;
  text-align: center;
  line-height: 24px;
  font-size: 10px;
  color: #fff;
  background-color: #4a5064;
}
.el-main{
    height: 90vh;
    overflow-y: auto;
}
</style>
